/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * OrderFrame.java
 *
 * Created on 28-11-2011, 10:30:26
 */
package GUILag;
import ControllerLag.*;
import ModelLag.*;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JTable;
import java.util.GregorianCalendar;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.RowSorter;
import javax.swing.SortOrder;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;

/**
 *
 * @author Ronni
 */
public class OrderFrame extends javax.swing.JFrame {

    private CustomerCTR customerCTR;
    private EmployeeCTR employeeCTR;
    private EventCTR eventCTR;
    private MenuCTR menuCTR;
    private OrderArrCTR orderArrCTR;
    private RoomCTR roomCTR;
    private LaneCTR laneCTR;
    private GregorianCalendar newCal = new GregorianCalendar();
    private SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
    private SimpleDateFormat dateFormat2 = new SimpleDateFormat("-MM-yyyy");
    private SimpleDateFormat dateFormat3 = new SimpleDateFormat("HH:MM");
    private MyTableCellRenderer newRenderer;
    private static OrderFrame _instance = null; // singleton
    /** Creates new form OrderFrame */
    private OrderFrame() {
        customerCTR = new CustomerCTR();
        employeeCTR = new EmployeeCTR();
        eventCTR = new EventCTR();
        menuCTR = new MenuCTR();
        orderArrCTR = new OrderArrCTR();
        roomCTR = new RoomCTR();
        laneCTR = new LaneCTR();
        initComponents();
        newRenderer = new MyTableCellRenderer();
        //SETS the period start text to todays date
        pStartTxt.setText(dateFormat.format(newCal.getTime()));
        Integer daysInMonth = newCal.getActualMaximum(GregorianCalendar.DAY_OF_MONTH);
        //Sets the period end text to the last day of the month
        pEndTxt.setText(daysInMonth + dateFormat2.format(newCal.getTime()));
        //prints the period from todays date, to the last of the month
        printOrderArr(orderArrCTR.getEverythingOrderArr(true, pStartTxt.getText(), pEndTxt.getText()));

        //Set column horizontal sizes
        orderArrTable.getColumnModel().getColumn(0).setPreferredWidth(60);
        orderArrTable.getColumnModel().getColumn(1).setPreferredWidth(80);
        orderArrTable.getColumnModel().getColumn(2).setPreferredWidth(40);
        orderArrTable.getColumnModel().getColumn(3).setPreferredWidth(40);
        orderArrTable.getColumnModel().getColumn(4).setPreferredWidth(80);
        orderArrTable.getColumnModel().getColumn(5).setPreferredWidth(60);
        orderArrTable.getColumnModel().getColumn(6).setPreferredWidth(45);
        orderArrTable.getColumnModel().getColumn(7).setPreferredWidth(85);
    }
   
    public static OrderFrame getInstance()
    {
        if(_instance == null)
        {
            _instance = new OrderFrame();
        }
        return _instance;
    }

    //Populates the comboboxes in iterations, uses objects in the comboboxes for easy access when creating order
    // 
    public void populateComboBoxes() 
            
            
{
    comboArr.removeAllItems();
    comboAmountLanes.removeAllItems();
    comboEmpl.removeAllItems();
    comboRooms.removeAllItems();
            for(Event events : eventCTR.getAllEvent())
            {
                comboArr.addItem(events.getEventName());
                
            }
            
            for(Lane lanes : laneCTR.getAllLanes())
            {
                comboAmountLanes.addItem(lanes);
            }
            for(Room rooms : roomCTR.getAllRooms() )
            {
                comboRooms.addItem(rooms.getRoomName());
            }
            comboEmpl.removeAllItems();
            for(Employee employees : employeeCTR.getAllEmployees() )
            {
                if(employees.isActive())
                {
                comboEmpl.addItem(employees);
                }
            }            
    
}
// gets the order-table model, needed to work with the tablemodel
 private DefaultTableModel getOrderModel()
    {
        return (DefaultTableModel) orderArrTable.getModel();
    }
  private DefaultTableModel getCustomerModel()
    {
        return (DefaultTableModel) customerTable.getModel();
    }
    
//adds a row to the order table model, with inputvariables needed for this
    private void addRowAndDataToOrderTable(int orderID, GregorianCalendar date, String startTime, String endTime, String bowlingFrom,int amountLanes, int amountPersons, int amountPersonsNoFood, String description, String customerName, String roomName, String employeeName, String eventName, boolean sort)
    {
        SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-YYYY");
        Date newDate = null;
        
        newDate = date.getTime();

        //Object[] data2 = {1000,new Date(), "14:00","14:00","14:00",1,1,1,"hej","bent","rum","rh","bøf"};
        
        Object[] data = {orderID, newDate,startTime,endTime,bowlingFrom,amountLanes, amountPersons,amountPersonsNoFood, description, customerName, roomName, employeeName,eventName};
        
        getOrderModel().addRow(data);
        int maxRows = getOrderModel().getRowCount();
        int thisRow = 0;
        if(maxRows > thisRow)
        {
            newRenderer.getTableCellRendererComponent(orderArrTable, eventName, false, false, thisRow, 13);
            thisRow++;
        }
        
        
        
        
        
        if(sort)
        {
            sortTable();
        }
    }
    public void addRowAndDataToCustomerTable(String phoneNo, String fName, String lName, String address, String zipCode, String email, boolean sort )
            
    {  
        
        Object[] data = {phoneNo,fName,lName,address,zipCode,email};
        getCustomerModel().addRow(data);
        
        if(sort)
        {
            sortTable();
        }
    }    
    //Sorts the table, on the table model
    private void sortTable()
    {
        TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(getOrderModel());
        List <RowSorter.SortKey> sortKeys = new ArrayList<RowSorter.SortKey>();
        sortKeys.add(new RowSorter.SortKey(1, SortOrder.ASCENDING));
        sorter.setSortKeys(sortKeys);
        orderArrTable.setRowSorter(sorter);
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel4 = new javax.swing.JPanel();
        jLabel29 = new javax.swing.JLabel();
        comboArr = new javax.swing.JComboBox();
        jLabel30 = new javax.swing.JLabel();
        jLabel31 = new javax.swing.JLabel();
        jLabel34 = new javax.swing.JLabel();
        createOrderBtn = new javax.swing.JButton();
        jScrollPane4 = new javax.swing.JScrollPane();
        txtDesc = new javax.swing.JTextArea();
        comboAmountLanes = new javax.swing.JComboBox();
        txtName = new javax.swing.JTextField();
        txtPhoneNo = new javax.swing.JTextField();
        jLabel36 = new javax.swing.JLabel();
        jLabel37 = new javax.swing.JLabel();
        jLabel38 = new javax.swing.JLabel();
        jLabel39 = new javax.swing.JLabel();
        jLabel40 = new javax.swing.JLabel();
        comboRooms = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        comboEmpl = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        searchField = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        txtEndTime = new javax.swing.JFormattedTextField();
        txtStartTime = new javax.swing.JFormattedTextField();
        txtAmountPersons = new javax.swing.JFormattedTextField();
        txtPersOnlyFood = new javax.swing.JFormattedTextField();
        txtBowlingFrom = new javax.swing.JFormattedTextField();
        txtDate = new javax.swing.JFormattedTextField();
        jPanel2 = new javax.swing.JPanel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        radio1 = new javax.swing.JRadioButton();
        radio2 = new javax.swing.JRadioButton();
        pStartTxt = new javax.swing.JTextField();
        pEndTxt = new javax.swing.JTextField();
        jScrollPane2 = new javax.swing.JScrollPane();
        orderArrTable = new javax.swing.JTable();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        customerTable = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Arrangementer");
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setResizable(false);

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Opret Arrangement"));

        jLabel29.setText("Antal Baner");

        comboArr.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                comboArrItemStateChanged(evt);
            }
        });
        comboArr.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboArrActionPerformed(evt);
            }
        });

        jLabel30.setText("Navn");

        jLabel31.setText("Antal Personer");

        jLabel34.setText("Tlf Nr");

        createOrderBtn.setText("Opret Arrangement");
        createOrderBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                createOrderBtnActionPerformed(evt);
            }
        });

        txtDesc.setColumns(20);
        txtDesc.setRows(5);
        jScrollPane4.setViewportView(txtDesc);

        txtName.setEditable(false);
        txtName.setEnabled(false);
        txtName.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtNameActionPerformed(evt);
            }
        });
        txtName.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtNameKeyReleased(evt);
            }
        });

        txtPhoneNo.setEditable(false);
        txtPhoneNo.setEnabled(false);
        txtPhoneNo.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtPhoneNoKeyReleased(evt);
            }
        });

        jLabel36.setText("Arrangement");

        jLabel37.setText("Dato");

        jLabel38.setText("Slut tidspunkt");

        jLabel39.setText("Start tidspunkt");

        jLabel40.setText("Lokale");

        jLabel2.setText("Hurtigsøgning");

        jLabel1.setText("Medarb");

        jLabel3.setText("Pers. uden bowl");

        jLabel4.setText("Bowling Fra");

        searchField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                searchFieldKeyReleased(evt);
            }
        });

        jLabel5.setText("Kommentarer til ordre:");

        txtEndTime.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(java.text.DateFormat.getTimeInstance(java.text.DateFormat.SHORT))));

        txtStartTime.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(java.text.DateFormat.getTimeInstance(java.text.DateFormat.SHORT))));
        txtStartTime.setToolTipText("");

        txtAmountPersons.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0"))));

        txtPersOnlyFood.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0"))));

        txtBowlingFrom.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(java.text.DateFormat.getTimeInstance(java.text.DateFormat.SHORT))));

        txtDate.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter()));
        txtDate.setToolTipText("");
        txtDate.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtDateFocusLost(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 352, Short.MAX_VALUE)
                    .addComponent(createOrderBtn)
                    .addComponent(jLabel5)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel36)
                            .addComponent(jLabel37)
                            .addComponent(jLabel30)
                            .addComponent(jLabel39)
                            .addComponent(jLabel31)
                            .addComponent(jLabel4)
                            .addComponent(jLabel40))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(txtDate, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtName, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtStartTime, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtAmountPersons, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtBowlingFrom, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(comboRooms, javax.swing.GroupLayout.Alignment.LEADING, 0, 77, Short.MAX_VALUE))
                                .addGap(14, 14, 14)
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel1)
                                    .addComponent(jLabel29)
                                    .addComponent(jLabel38)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel34)
                                    .addComponent(jLabel2))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 7, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(txtPhoneNo, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 102, Short.MAX_VALUE)
                                    .addComponent(comboAmountLanes, javax.swing.GroupLayout.Alignment.LEADING, 0, 102, Short.MAX_VALUE)
                                    .addComponent(comboEmpl, javax.swing.GroupLayout.Alignment.LEADING, 0, 102, Short.MAX_VALUE)
                                    .addComponent(txtEndTime, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 102, Short.MAX_VALUE)
                                    .addComponent(txtPersOnlyFood, javax.swing.GroupLayout.DEFAULT_SIZE, 102, Short.MAX_VALUE)
                                    .addComponent(searchField, javax.swing.GroupLayout.DEFAULT_SIZE, 102, Short.MAX_VALUE)))
                            .addComponent(comboArr, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel36)
                    .addComponent(comboArr, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(searchField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addGap(58, 58, 58)
                                .addComponent(txtPersOnlyFood, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addGap(6, 6, 6)
                                .addComponent(txtPhoneNo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtEndTime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(32, 32, 32)
                                .addComponent(comboAmountLanes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(comboEmpl, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel37)
                            .addComponent(jLabel2)
                            .addComponent(txtDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel30)
                            .addComponent(jLabel34)
                            .addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel39)
                            .addComponent(jLabel38)
                            .addComponent(txtStartTime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(6, 6, 6)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel31)
                            .addComponent(jLabel3)
                            .addComponent(txtAmountPersons, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(jLabel29)
                            .addComponent(txtBowlingFrom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(comboRooms, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel40)
                            .addComponent(jLabel1))
                        .addGap(14, 14, 14)
                        .addComponent(jLabel5)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(26, 26, 26)
                .addComponent(createOrderBtn)
                .addContainerGap(16, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Arrangementer"));
        jPanel2.setMaximumSize(new java.awt.Dimension(1280, 700));
        jPanel2.setMinimumSize(new java.awt.Dimension(1280, 700));
        jPanel2.setPreferredSize(new java.awt.Dimension(1280, 700));

        jLabel12.setText("Søgning");

        jLabel13.setText("Søgekriterier");

        buttonGroup1.add(radio1);
        radio1.setText("Alle Arrangementer");
        radio1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                radio1ActionPerformed(evt);
            }
        });

        buttonGroup1.add(radio2);
        radio2.setSelected(true);
        radio2.setText("Periode");
        radio2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                radio2ActionPerformed(evt);
            }
        });

        pStartTxt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pStartTxtActionPerformed(evt);
            }
        });

        orderArrTable.setAutoCreateRowSorter(true);
        orderArrTable.setBackground(new java.awt.Color(153, 255, 153));
        orderArrTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "OrdreID", "Dato", "Spise", "Slut", "Bowlingfra", "Baneantal", "Pers.", "Pers.KunSpise","Beskrivelse", "Kunde", "Lokale", "Medarbejder", "Arrangement"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.util.Date.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false, false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }

        });
        orderArrTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_LAST_COLUMN);
        orderArrTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        orderArrTable.getTableHeader().setReorderingAllowed(false);
        orderArrTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                orderArrTableMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(orderArrTable);

        jLabel14.setText("Periode Start");

        jLabel15.setText("Periode Slut");

        jButton2.setText("Søg...");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setText("Slet Arrangement");
        jButton3.setPreferredSize(new java.awt.Dimension(80, 20));
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton5.setText("Vis valgte arrangement");
        jButton5.setPreferredSize(new java.awt.Dimension(80, 20));
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jButton6.setText("Luk");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        jLabel6.setText("Ordre");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 834, Short.MAX_VALUE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(radio1)
                                    .addComponent(radio2)))
                            .addComponent(jLabel13)))
                    .addComponent(jLabel12)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel14)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(pStartTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel15)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(pEndTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton2))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(16, 16, 16)
                        .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 194, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(775, 775, 775)
                        .addComponent(jButton6))
                    .addComponent(jLabel6))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jLabel12)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel13)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(radio1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(radio2)
                .addGap(19, 19, 19)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel14)
                    .addComponent(pStartTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel15)
                    .addComponent(pEndTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel6)
                .addGap(6, 6, 6)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 446, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(31, Short.MAX_VALUE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
        );

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Kundeinformation"));

        customerTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Tlf", "Fornavn", "Efternavn", "Adresse", "Postnr", "Email"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        customerTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                customerTableMouseReleased(evt);
            }
        });
        jScrollPane1.setViewportView(customerTable);

        jButton1.setText("Ny Kunde");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton4.setText("Rediger Kunde");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton4))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 352, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 171, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton4))
                .addContainerGap(34, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 866, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 679, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

//Creates the order: the first line here typecasts the object gotten from the combobox from Object -> Employee
private void createOrderBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createOrderBtnActionPerformed
Employee employee = (Employee)comboEmpl.getSelectedItem(); 
int pers = Integer.parseInt(txtAmountPersons.getText());
int persOnlyFood = Integer.parseInt(txtPersOnlyFood.getText());
int startTimeMin = (Integer.parseInt(txtStartTime.getText().substring(0,2)))*60 + Integer.parseInt(txtStartTime.getText().substring(3,5));
int endTimeMin = (Integer.parseInt(txtEndTime.getText().substring(0,2)))*60 + Integer.parseInt(txtEndTime.getText().substring(3,5));
            

    if(pers < persOnlyFood || startTimeMin >= endTimeMin)
    {
        String message = "Der er sket en fejl under ordreoprettelse, kontroller at felterne er udfyldt korrekt";
        Object[] options = {"Ok"};
        JOptionPane.showOptionDialog(this, message, "Der er sket en fejl.", JOptionPane.ERROR_MESSAGE, JOptionPane.ERROR_MESSAGE, null, options, "");    
    }
    else
    {
    try
    {
        int rc = orderArrCTR.createOrderArr(orderArrCTR.getNextOrderID(),txtDate.getText().trim(), txtStartTime.getText().trim(), txtEndTime.getText().trim(), Integer.parseInt(comboAmountLanes.getSelectedItem().toString().trim()), Integer.parseInt(txtAmountPersons.getText().trim()),Integer.parseInt(txtPersOnlyFood.getText().trim()),customerCTR.findCustomer(txtPhoneNo.getText().trim()),employee,roomCTR.findByName(comboRooms.getSelectedItem().toString().trim()), eventCTR.findEvent(comboArr.getSelectedItem().toString().trim()), txtDesc.getText().trim(), txtBowlingFrom.getText().trim());
    
    if(rc ==1)
    {
    OrderArr newOrder = orderArrCTR.findOrderArr(orderArrCTR.getNextOrderID() - 1);
    GregorianCalendar theDate = new GregorianCalendar();
    theDate.setTime(newOrder.getDate().getTime());
    addRowAndDataToOrderTable(newOrder.getOrderID(),theDate, newOrder.getStartTime().substring(0, 5), newOrder.getEndTime().substring(0, 5), newOrder.getBowlingFrom().substring(0, 5),newOrder.getAmountOfLanes(), newOrder.getNoOfPersons(),newOrder.getNoOfPersonsOnlyFood(), newOrder.getDescription(),newOrder.getCustomer().getfName() + " " + newOrder.getCustomer().getlName(),newOrder.getRoom().getRoomName(),newOrder.getEmployee().getfName() + " " + newOrder.getEmployee().getlName(), newOrder.getEvent().getEventName(),false);    
    sortTable();
    }else{
        String message = "Der er sket en fejl under ordreoprettelse, kontroller at felterne er udfyldt korrekt";
        Object[] options = {"Ok"};
        JOptionPane.showOptionDialog(this, message, "Der er sket en fejl.", JOptionPane.ERROR_MESSAGE, JOptionPane.ERROR_MESSAGE, null, options, "");    
    
    }
    
    }catch(Exception e){
        String message = "Der er sket en fejl under ordreoprettelse, kontroller at felterne er udfyldt korrekt";
        Object[] options = {"Ok"};
        JOptionPane.showOptionDialog(this, message, "Der er sket en fejl.", JOptionPane.ERROR_MESSAGE, JOptionPane.ERROR_MESSAGE, null, options, "");    
    }
    }
    
}//GEN-LAST:event_createOrderBtnActionPerformed

private void txtNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtNameActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_txtNameActionPerformed

private void txtNameKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNameKeyReleased

}//GEN-LAST:event_txtNameKeyReleased

private void radio1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radio1ActionPerformed
    radio2.setSelected(false);
    pStartTxt.setEnabled(false);
    pEndTxt.setEnabled(false); 
}//GEN-LAST:event_radio1ActionPerformed

private void radio2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radio2ActionPerformed
    radio1.setSelected(false);
    pStartTxt.setEnabled(true);
    pEndTxt.setEnabled(true);
}//GEN-LAST:event_radio2ActionPerformed

private void pStartTxtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pStartTxtActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_pStartTxtActionPerformed

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
try
{
    if(radio1.isSelected())
{
    printOrderArr(orderArrCTR.getEverythingOrderArr(false,"",""));

}
if(radio2.isSelected())
{
     printOrderArr(orderArrCTR.getEverythingOrderArr(true,pStartTxt.getText(), pEndTxt.getText()));
}
}
catch(Exception e){
    String message = "Der er sket en fejl under søgningen, indtast korrekt periode : dd-mm-yyyy";
    Object[] options = {"Ok"};
    JOptionPane.showOptionDialog(this, message, "Der er sket en fejl.", JOptionPane.ERROR_MESSAGE, JOptionPane.ERROR_MESSAGE, null, options, "");        
}
}//GEN-LAST:event_jButton2ActionPerformed

private void txtPhoneNoKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtPhoneNoKeyReleased

}//GEN-LAST:event_txtPhoneNoKeyReleased

private void customerTableMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_customerTableMouseReleased

    try{
    txtName.setText(customerTable.getValueAt(customerTable.getSelectedRow(), 1).toString().trim() + " " + customerTable.getValueAt(customerTable.getSelectedRow(), 2).toString().trim());
    txtPhoneNo.setText(customerTable.getValueAt(customerTable.getSelectedRow(), 0).toString().trim());
    customerTable.getValueAt(customerTable.getSelectedRow(), customerTable.getSelectedColumn());
    }catch(Exception e){
        String message = "Der er sket en fejl under kundevalg, kunden eksisterer muligvis ikke";
        Object[] options = {"Ok"};
        JOptionPane.showOptionDialog(this, message, "Der er sket en fejl.", JOptionPane.ERROR_MESSAGE, JOptionPane.ERROR_MESSAGE, null, options, "");    
    }
    
}//GEN-LAST:event_customerTableMouseReleased

private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
 this.dispose();
}//GEN-LAST:event_jButton6ActionPerformed

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
try{
    ViewOrderForm viewOrder = new ViewOrderForm(Integer.parseInt(orderArrTable.getValueAt(orderArrTable.getSelectedRow(), 0).toString()),this, orderArrTable.getSelectedRow() );
    viewOrder.setVisible(true);
    viewOrder.setLocation(500, 100);
    this.setEnabled(false);
    }catch(Exception e)
    {
     String message2 = "Der er sket en fejl under visning af ordre, har du valgt en ordre?";
     Object[] options2 = {"Ok"};
     JOptionPane.showOptionDialog(this, message2, "Der er sket en fejl.", JOptionPane.ERROR_MESSAGE, JOptionPane.ERROR_MESSAGE, null, options2, "");    
     System.out.println(e);       
    }

}//GEN-LAST:event_jButton5ActionPerformed

public void updateRow(int orderID, GregorianCalendar date, String startTime, String endTime, int amountLanes, int noOfPersons, int noOfPersonsFood, String theCustomer, String theEmployee, String room, String event, String description, String bowlingFrom, int row)
{
        SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-YYYY");
        Date newDate = new Date();
        newDate.setTime(date.getTimeInMillis());    
    try{
    orderArrTable.setValueAt(orderID, row, 0);
    orderArrTable.setValueAt(newDate, row, 1);
    orderArrTable.setValueAt(startTime, row, 2);
    orderArrTable.setValueAt(endTime, row, 3);
    orderArrTable.setValueAt(bowlingFrom, row, 4);
    orderArrTable.setValueAt(amountLanes, row, 5);
    orderArrTable.setValueAt(noOfPersons, row, 6);
    orderArrTable.setValueAt(noOfPersonsFood, row, 7);
    orderArrTable.setValueAt(description, row, 8);
    orderArrTable.setValueAt(theCustomer, row, 9);
    orderArrTable.setValueAt(room, row, 10);
    orderArrTable.setValueAt(theEmployee, row, 11);
    orderArrTable.setValueAt(event, row, 12);
    }catch(Exception e)
    {
        System.out.println(e);
    }
}

public void updateCustomerRow(String phoneNo, String fName, String lName, String address, String zipCode,String email, int row)
{
    try{
    customerTable.setValueAt(phoneNo, row, 0);
    customerTable.setValueAt(fName, row, 1);
    customerTable.setValueAt(lName, row, 2);
    customerTable.setValueAt(address, row, 3);
    customerTable.setValueAt(zipCode, row, 4);
    customerTable.setValueAt(email, row, 5);
    }catch(Exception e)
    {
        System.out.println(e);
    }
}
private int[] getScreenDimensions()
{
    Toolkit tk = Toolkit.getDefaultToolkit();
    Dimension screenSize = tk.getScreenSize();
    int sizes[] = {screenSize.height ,screenSize.width};
    System.out.println(""+ sizes[0] + ""+sizes[1]);
    return sizes;
}
private void removeRow(int rowNo)
    {
        rowNo = orderArrTable.convertRowIndexToModel(rowNo);
        getOrderModel().removeRow(rowNo);
    }

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
 try{    
        SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
        GregorianCalendar newDate = new GregorianCalendar();
        newDate.setTime((Date)orderArrTable.getValueAt(orderArrTable.getSelectedRow(), 1));
        String arrDate = sdf.format(newDate.getTime());
        String arrCustomer = orderArrTable.getValueAt(orderArrTable.getSelectedRow(), 9).toString();
        String arrEvent = orderArrTable.getValueAt(orderArrTable.getSelectedRow(), 12).toString();
        String message = "Vil du slette: " + arrCustomer + "'s " + arrEvent + " arrangement d. " + arrDate + "?";
        Object[] options = {"Ja", "Nej"};
        int input = JOptionPane.showOptionDialog(this, message, "Vil du virkeligt slette dette arrangement?", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, "");
                if(input == JOptionPane.YES_OPTION)
        {   
            orderArrCTR.deleteOrderArr(Integer.parseInt(orderArrTable.getValueAt(orderArrTable.getSelectedRow(), 0).toString()));
            removeRow(orderArrTable.getSelectedRow());
            
            
        }
    }catch(Exception e){
                 String message2 = "Der er sket en fejl sletning, arrangementet eksisterer muligvis ikke";
                 Object[] options2 = {"Ok"};
                 JOptionPane.showOptionDialog(this, message2, "Der er sket en fejl.", JOptionPane.ERROR_MESSAGE, JOptionPane.ERROR_MESSAGE, null, options2, "");    
    
        }          
        
}//GEN-LAST:event_jButton3ActionPerformed

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
try{
    CreateCustomerPanel createPanel = new CreateCustomerPanel(this);
    createPanel.setLocationByPlatform(true);
    this.setEnabled(false);
    createPanel.setVisible(true);
    createPanel.setLocation(500,100);
    
        }catch(Exception e){
        String message = "Der er sket en fejl under kundevalg, kunden eksisterer muligvis ikke";
        Object[] options = {"Ok"};
        JOptionPane.showOptionDialog(this, message, "Der er sket en fejl.", JOptionPane.ERROR_MESSAGE, JOptionPane.ERROR_MESSAGE, null, options, "");    
    }   
  
}//GEN-LAST:event_jButton1ActionPerformed

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
try{
    Customer newCust = customerCTR.findCustomer(customerTable.getValueAt(customerTable.getSelectedRow(), 0).toString());
    UpdateCustomerPanel updatePanel = new UpdateCustomerPanel(newCust,this,customerTable.getSelectedRow());
    this.setEnabled(false);
    updatePanel.setVisible(true); 
    updatePanel.setLocation(500,100);
        }catch(Exception e){
            String message = "Der er sket en fejl under kundevalg, kunden eksisterer muligvis ikke";
        Object[] options = {"Ok"};
        System.out.println(e);
        JOptionPane.showOptionDialog(this, message, "Der er sket en fejl.", JOptionPane.ERROR_MESSAGE, JOptionPane.ERROR_MESSAGE, null, options, "");    
    }

    
}//GEN-LAST:event_jButton4ActionPerformed

    private void comboArrActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboArrActionPerformed
        
    }//GEN-LAST:event_comboArrActionPerformed
//dynamicly searches for customers, when a key is released
private void searchFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_searchFieldKeyReleased
    getCustomerModel().setRowCount(0);
    if(!searchField.getText().equals(""))
    {
    for(Customer customers : customerCTR.searchCustomer(searchField.getText().trim()))
    {
        String phoneNo = customers.getPhoneNo();
        String fName = customers.getfName();
        String lName = customers.getlName();
        String address = customers.getAddress();
        String zipCode = customers.getZipCode();
        String email = customers.getEmail();
        addRowAndDataToCustomerTable(phoneNo,fName,lName,address,zipCode,email,false);
    }
    }
}//GEN-LAST:event_searchFieldKeyReleased
//doubleclick on an order, opens the viewOrderfram, with the selected order
private void orderArrTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_orderArrTableMouseClicked
            int selectedOrder = 0;
            selectedOrder = Integer.parseInt(orderArrTable.getValueAt(orderArrTable.getSelectedRow(), 0).toString());
            if (evt.getClickCount() == 2 && selectedOrder != 0 && evt.getButton() == 1)
            {
            try{
            ViewOrderForm viewOrder = new ViewOrderForm(Integer.parseInt(orderArrTable.getValueAt(orderArrTable.getSelectedRow(), 0).toString()),this, orderArrTable.getSelectedRow() );
            viewOrder.setLocation(500, 100);
            viewOrder.setVisible(true);
            this.setEnabled(false);
            }catch(Exception e)
            {
            String message2 = "Der er sket en fejl under visning af ordre, har du valgt en ordre?";
            Object[] options2 = {"Ok"};
            JOptionPane.showOptionDialog(this, message2, "Der er sket en fejl.", JOptionPane.ERROR_MESSAGE, JOptionPane.ERROR_MESSAGE, null, options2, "");    
            System.out.println(e);       
            }
           
            }
}//GEN-LAST:event_orderArrTableMouseClicked

private void comboArrItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_comboArrItemStateChanged
    
}//GEN-LAST:event_comboArrItemStateChanged

private void txtDateFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtDateFocusLost
//    try{
//    if(!txtDate.getText().substring(3, 3).equals("-") && !txtDate.getText().substring(6,6).equals("-") && txtDate.getText().length() != 10)
//    {
//        System.out.print("notcorrect");
//    }else{
//        System.out.print("correct");
//    }
//    }catch(IndexOutOfBoundsException e)
//    {
//        System.out.println(e);
//    }
//    
}//GEN-LAST:event_txtDateFocusLost
  //Prints the orders from an arraylist of orders to the table model
    private void printOrderArr(ArrayList<OrderArr> arrayList)
    {
        getOrderModel().setRowCount(0);
        for(OrderArr orders : arrayList)
        {
            int orderID = orders.getOrderID();
            GregorianCalendar date = new GregorianCalendar();
            date.setTime(orders.getDate().getTime());
            String startTime = orders.getStartTime().substring(0, 5);
            String endTime = orders.getEndTime().substring(0, 5);        
            String bowlingFrom = orders.getBowlingFrom().substring(0, 5);         
            int amountOfLanes = orders.getAmountOfLanes();
            int noPersons = orders.getNoOfPersons();
            int noPersonsOnlyFood = orders.getNoOfPersonsOnlyFood();
            String description = orders.getDescription();
            String roomName = orders.getRoom().getRoomName();
            String customerName = orders.getCustomer().getfName() + " " + orders.getCustomer().getlName();
            String employeeName = orders.getEmployee().getfName() + " " + orders.getEmployee().getlName();
            String eventName = orders.getEvent().getEventName();
            addRowAndDataToOrderTable(orderID, date, startTime, endTime, bowlingFrom,amountOfLanes, noPersons, noPersonsOnlyFood, description, customerName, roomName, employeeName,eventName,false);
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JComboBox comboAmountLanes;
    private javax.swing.JComboBox comboArr;
    private javax.swing.JComboBox comboEmpl;
    private javax.swing.JComboBox comboRooms;
    private javax.swing.JButton createOrderBtn;
    private javax.swing.JTable customerTable;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel29;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel30;
    private javax.swing.JLabel jLabel31;
    private javax.swing.JLabel jLabel34;
    private javax.swing.JLabel jLabel36;
    private javax.swing.JLabel jLabel37;
    private javax.swing.JLabel jLabel38;
    private javax.swing.JLabel jLabel39;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel40;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JTable orderArrTable;
    private javax.swing.JTextField pEndTxt;
    private javax.swing.JTextField pStartTxt;
    private javax.swing.JRadioButton radio1;
    private javax.swing.JRadioButton radio2;
    private javax.swing.JTextField searchField;
    private javax.swing.JFormattedTextField txtAmountPersons;
    private javax.swing.JFormattedTextField txtBowlingFrom;
    private javax.swing.JFormattedTextField txtDate;
    private javax.swing.JTextArea txtDesc;
    private javax.swing.JFormattedTextField txtEndTime;
    private javax.swing.JTextField txtName;
    private javax.swing.JFormattedTextField txtPersOnlyFood;
    private javax.swing.JTextField txtPhoneNo;
    private javax.swing.JFormattedTextField txtStartTime;
    // End of variables declaration//GEN-END:variables
}
